#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：pythonProject2 
@File    ：hero_exe.py
@Author  ：beibei
@Date    ：2024/3/26 3:55 PM 
'''
# import requests
# import os
#
# # 获取所有英雄的列表
# def fetch_hero_list1():
#     url = 'https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js?v=20'
#     response = requests.get(url)
#     if response.status_code == 200:
#         data = response.json()
#         return data.get('hero', [])
#     else:
#         return []
#
# # 获取指定英雄的所有皮肤信息
# def fetch_hero_skins2(hero_id):
#     url = f'https://game.gtimg.cn/images/lol/act/img/js/hero/{hero_id}.js'
#     response = requests.get(url)
#     if response.status_code == 200:
#         data = response.json()
#         return data.get('skins', [])
#     else:
#         return []
#
# # 保存皮肤图片
# def save_skin_image3(skin_id, skin_name, hero_name):
#     url = f'https://game.gtimg.cn/images/lol/act/img/skin/big{skin_id}.jpg'
#     try:
#         response = requests.get(url)
#         response.raise_for_status()  # 如果响应不是200，将引发异常
#         img_data = response.content
#         home_directory = os.path.expanduser('~')
#         save_path = os.path.join(home_directory, 'Desktop', 'lol_skins', hero_name)
#         os.makedirs(save_path, exist_ok=True)
#         with open(os.path.join(save_path, f'{skin_name}.jpg'), 'wb') as file:
#             file.write(img_data)
#         print(f'皮肤 {skin_name} 已保存')
#     except requests.exceptions.HTTPError as e:
#         if e.response.status_code == 404:
#             print(f'皮肤 {skin_name} 不存在，跳过')
#         else:
#             print(f'下载皮肤 {skin_name} 时出现错误: {e}')
#     except Exception as e:
#         print(f'保存皮肤 {skin_name} 时出现错误: {e}')
#
# # 主函数
# def main4():
#     heroes = fetch_hero_list1()
#     for hero in heroes:
#         hero_id = hero['heroId']
#         hero_name = hero['name']
#         print(f'正在处理英雄 {hero_name}')
#         skins = fetch_hero_skins2(hero_id)
#         for skin in skins:
#             if skin['name'] != 'default':
#                 save_skin_image3(skin['skinId'], skin['name'], hero_name)
#
# if __name__ == '__main__':
#     main4()

